#pragma once
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class IProgress {
public:
    virtual ~IProgress() 
    {

    }

    virtual void DoProgress(double value) = 0;

};

struct ProgressBar
{
    /* data */
public:
    void setValue(int value) {
        
    }
};

class FileSplitter
{
private:
    string m_filePath;
    int m_fileNumber;

    // 具体通知控件
    // ProgressBar *m_progressBar;

    // 抽象通知控件
    // IProgress *m_iprogress;

    // 多个抽象通知控件
    vector<IProgress*> m_iprogressList;

public:
    FileSplitter(const string& filePath
        , int fileNumber);

    ~FileSplitter();

    void split();
    
    void add_IProgress(IProgress *iprogress)
    {
        m_iprogressList.emplace_back(iprogress);
    }

    void remove_IProgress(IProgress *iprogress)
    {
        // m_iprogressList.remove();
    }

protected:
    void onProgress(double value) 
    {
        // 更新每一个进度条
        for (auto iprogress : m_iprogressList)
        if (iprogress) {
            iprogress->DoProgress(value);
        }
    }
};

FileSplitter::FileSplitter(const string& filePath
        , int fileNumber) :
    m_filePath(filePath)
    , m_fileNumber(fileNumber)
    // , m_iprogress(progress)

{
}

FileSplitter::~FileSplitter()
{
}

void FileSplitter::split()
{
    // 1. 读取大文件

    // 2. 分批次向小文件中写入
    for (size_t i = 0; i < m_fileNumber; i++)
    {
        /* code */
        double progressValue = m_fileNumber;
        progressValue = (i + 1) / m_fileNumber;
        
        onProgress(progressValue);
    }
    
}

